扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
代码
/**
* TextBox´´s instance
*/
private TextBox inputName = null;
/**
* 「cancel」Command
* command in TextBox
*/
private Command cCancel = new Command("cancel", Command.CANCEL, 1);
/**
* 「ok」Command
* command in TextBox
*/
private Command cOK = new Command("ok", Command.OK, 1);
/**
* 保存在TextBox中已输入的值
*/
private String name = "";
/**
* 调用TextBox
* The method disposes the key pressing action
* the code of pressed key
* @param key
*/
public void keyPressed(int key) {
if (key == Canvas.FIRE) {
inputName = new TextBox("请输入姓名", name, 8, TextField.ANY);
inputName.addCommand(cCancel);
inputName.addCommand(cOK);
inputName.setCommandListener(this);
Display.getDisplay(BustRoyal.instance).setCurrent(inputName);
//其中BustRoyal.instance为MIDlet的实例
}
}
/**
* TextBox中的command的处理
*/
public void commandAction(Command c, Displayable d) {
if (c == cCancel) {
Display.getDisplay(BustRoyal.instance).setCurrent(this);
} else if (c == cOK) {
name = inputName.getString().trim();
Display.getDisplay(BustRoyal.instance).setCurrent(this);
}
}
婵犵鈧啿鈧綊鎮樻径鎰畺闁靛ň鏅滄慨婊堟偨椤栨稓鎽冮柟鐑╂櫊瀹曟岸宕堕埡鍌滄殸闂佽鍨伴崢鏍姳閿涘嫭鍠嗘い銈呭姬婵☆偅婢樺Λ妤呮偂濞嗘挸瀚夐柍褜鍓熷顒侊紣娓氣偓閻涙捇鏌涘┑鍛樂缂佹鐭傞獮搴ㄥ焵椤掑嫬瀚夋い鏍ㄧ懁缁诲棝鏌熼褍鐏茬紒杈ㄧ箞閺屽洭鏁愰崟顓犳澖闁荤姳闄嶉崹钘壩i崟顖涘殜闁硅泛顫曢埀顒€锕︾槐鏃堝箣閻愬弬妤呮煛閸偄鐏﹂柛瀣墬缁傛帞鎹勯搹瑙勵啈闂佸搫瀚烽崹閬嶅磻瀹ュ鍎嶉柛鏇ㄥ墯娴犳ê霉閿濆棗鈻曢柍褜鍓氶弻銊ф閻愬鈻曢悗锝傛櫇椤忛亶鏌曢崱顓熷